
export default (menu) => {
  let arr = []
  for (let i = 0; i < menu.length; i++) {
    if (menu[i].component && menu[i].path ) {
      let route = {
        path: menu[i].path,
        name: menu[i].name,
        component: menu[i].component,
        title: menu[i].title,
        meta: {
          title: menu[i].title,
          bt: menu[i].title,
          pName: menu[i].name,
          mIndex: i,
          pIndex: -1,
          keepAlive:menu[i].keepAlive,
          permissions: menu[i].permissions,
        },
        children: []
      }
      menu[i].redirect && (route.redirect =  menu[i].redirect)
      let mc = menu[i].child || []
      for (let k = 0; k < mc.length; k++) {
        if (mc[k].hasGroup) {
          mc[k].collapsed = false;
          mc[k].child.map((child, n)=>{
            if (child.path && child.component) {
              let groupIndex = k
              if ( child.showName ) {
                let childNames = mc[k].child.map((ac)=>{
                  return ac.name
                })
                childNames.indexOf(child.showName) == -1 && (groupIndex = -1)
              }

              let bt_path = [];
              bt_path.push(route);
              if(mc[k]) {
                bt_path.push(mc[k])

                if(child) {
                  bt_path.push(child)
                }
              }
              let c = {
                path: child.path,
                name: route.name + '_' + child.name,
                component: child.component,
                title: child.title,
                meta: {
                  groupIndex: groupIndex,
                  title: child.title,
                  bt: route.title + ' ' + mc[k].title + ' ' + child.title,
                  bt_path: bt_path,
                  name: child.name,
                  pName: route.name,
                  showName: child.showName,
                  hasGroupChild: child.hasGroupChild,
                  pIndex: i,
                  mIndex: n,
                  keepAlive:child.keepAlive,
                  permissions: child.permissions,
                },
              }
              route.children.push(c)
            }
          })
        } else {
          if (mc[k].path && mc[k].component) {
            let bt_path = [];
            bt_path.push(route);
            if(mc[k]) {
              bt_path.push(mc[k])
            }
            let c = {
              path: mc[k].path,
              name: route.name + '_' + mc[k].name,
              component: mc[k].component,
              title: mc[k].title,
              meta: {
                groupIndex: -1,
                title: mc[k].title,
                name: mc[k].name,
                showName: mc[k].showName,
                bt: route.title + ' ' + mc[k].title,
                bt_path: bt_path,
                pName: route.name,
                pIndex: i,
                mIndex: k,
                keepAlive:menu[i].keepAlive,
                permissions: mc[k].permissions,
              },
            }
            route.children.push(c)
          }
        }
      }
      arr.push(route)
    }
  }
  return {
    route: arr,
  }
}